package com.xncoding.valid.config;

import com.xncoding.valid.Resolver.CustomHandlerMethodParameterResolver;
import com.xncoding.valid.Converter.CustomHttpMessageConverter;
import com.xncoding.valid.Converter.PackHttpMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Bean
    public CustomHttpMessageConverter customHttpMessageConverter() {
        return new CustomHttpMessageConverter() ;
    }


    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        converters.add(0,new PackHttpMessageConverter()) ;

        CustomHttpMessageConverter messageConvert = new CustomHttpMessageConverter() ;
        List<MediaType> supportedMediaTypes = new ArrayList<>() ;
        supportedMediaTypes.add(new MediaType("application", "fm")) ;
        messageConvert.setSupportedMediaTypes(supportedMediaTypes) ;
        converters.add(messageConvert) ;
//        WebMvcConfigurer.super.configureMessageConverters(converters);

    }


    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        CustomHandlerMethodParameterResolver customResolver = new CustomHandlerMethodParameterResolver() ;
        customResolver.setMessageConverter(customHttpMessageConverter()) ;
        resolvers.add(customResolver) ;
    }
}